<?

class cDebugger 
{
	
	private $msgs = array();
	public $maxExecTime = 5;
	public $debug = false;

	function __construct(cCms $cms) 
	{
		if (isset($_GET['dieat'])) {
			if ($this->maxExecTime>$_GET['dieat'] && $_GET['dieat']>0) $this->maxExecTime = $_GET['dieat'];
		}
		$this->cms = $cms;
		if (isset($_GET['debug'])) {
			$this->debug = true;
		}		
	}
	
	function log($message, $sender=null) 
	{
		$this->addMsg('event', $message, $sender);
		
		$et = $this->cms->getExecTime();
		
		if ($et>$this->maxExecTime) 
		{
			//echo implode("\n<br /> ",$this->msgs);
			throw new cException('Vyprsel casovy limit pro zpracovani pozadavku.');
			die();
		}
	}

	function warning($message, $sender=null) 
	{
		$this->addMsg('warning', $message, $sender);
	}
	
	function addMsg($kind, $text, $sender) 
	{		
		if ($this->debug) {
			echo '<br /><b style="color:red">'.$kind.' '.get_class($sender).'</b> - '.$text;
		}
	}

}

?>